import { http } from '../../utils/net'
Page({
  data: {
    page: 1,
    size: 10,
    count: -1,
    recordList: [],
    finish: false,
    nothing: false
  },
  getData() {
    http({
      url: '/api/index/index?method=cloud_brush_list',
      data: {
        page: this.data.page,
        size: this.data.size
      },
      isShowLoading: true,
      successCb:(res) => {
        if(res.data.count == 0) {
          this.setData({
            nothing: true,
            finish: true,
            page: 1,
            recordList: []
          })
        } else if(res.data.count <= res.data.data.length + this.data.recordList.length) {
          this.setData({
            recordList: [...this.data.recordList, ...res.data.data],
            count: res.data.count,
            finish: true
          })
        } else {
          this.setData({
            recordList: [...this.data.recordList, ...res.data.data],
            count: res.data.count
          })
        }
      }
    })
  },
  onLoad: function (options) {
    this.getData()
  },
  onPullDownRefresh: function () {
    this.setData({
      recordList: [],
      page: 1
    })
    this.getData()
  },
  onReachBottom: function () {
    if(this.data.finish) {
      return
    }
    this.setData({
      page: this.data.page++
    })
    this.getData()
  }
})